/**
 * 通用
 */
import request from "@/utils/request";

/**
 * 商品分类树
 */
export const getCategoryTree = (search = "") => {
  return request({
    url: `/mall/tenant/category/getcategoryList?search=${search}`,
    method: "get"
  });
};

/**
 * 获取商品日志
 */
export const getLog = productId => {
  return request({
    url: "/mall/common/product/logs",
    method: "post",
    data: {
      productId
    }
  });
};

/**
 * 获取商家端商品列表
 * @param {*} data 条件参数
 * @returns
 */
export const getBusinessList = data => {
  return request({
    url: "/mall/tenant/merchant/product/page",
    method: "post",
    data
  });
};

/**
 * 商品下架
 */
export const downBusiness = data => {
  return request({
    url: "/mall/tenant/business/operation/down",
    method: "post",
    data
  });
};
/**
 * 商品重新上架
 */
export const reListedBusiness = data => {
  return request({
    url: "/mall/tenant/merchant/products/reListing",
    method: "post",
    data
  });
};
/**
 * 商品上架
 */
export const upBusiness = data => {
  return request({
    url: "/mall/tenant/merchant/product/listing",
    method: "post",
    data
  });
};
/**
 * 批量修改名称
 */
export const editBusinessName = data => {
  return request({
    url: "/mall/tenant/merchant/product/batchChangeProductName",
    method: "post",
    data
  });
};
/**
 * 批量修改销量
 */
export const editBusinessSales = data => {
  return request({
    url: "/mall/tenant/merchant/product/batchChangeSaleNum",
    method: "post",
    data
  });
};

/**
 * 批量修改商品型号
 */
export const editBusinessModel = data => {
  return request({
    url: "/mall/tenant/merchant/product/batchSaveModeCode",
    method: "post",
    data
  });
};
/**
 * 修改排序
 */
export const editBusinessSort = data => {
  return request({
    url: "/mall/tenant/merchant/product/updateMerchantProductSort",
    method: "post",
    data
  });
};

/**
 * 获取数量
 */
export const getBusinessCount = data => {
  return request({
    url: "/mall/tenant/merchant/product/barProductTotal",
    method: "post",
    data
  });
};
/**
 * 商品删除
 */
export const deleteBusiness = data => {
  return request({
    url: "/mall/tenant/merchant/products/delete",
    method: "post",
    data
  });
};
/**
 * 撤回删除
 */
export const revokeDelete = data => {
  return request({
    url: "/mall/tenant/merchant/products/revokeDelete",
    method: "post",
    data
  });
};
/**
 * 彻底删除商品
 */
export const deleteBusinessCompletely = data => {
  return request({
    url: "/mall/tenant/merchant/products/remove",
    method: "post",
    data
  });
};
/**
 * 预发布删除商品
 */
export const releaseRemove = data => {
  return request({
    url: "/mall/tenant/merchant/products/release/remove",
    method: "post",
    data
  });
};

//获取价格变更明细
export const changeSkuDetail = props => {
  return request({
    url: "/mall/tenant/merchant/product/changeSkuDetail",
    method: "get",
    params: props
  });
};
//价格变更->我知道了
export const saveChange = props => {
  return request({
    url: "/mall/tenant/merchant/product/saveChange",
    method: "post",
    data: props
  });
};
//返还平台
export const returnPlat = props => {
  return request({
    url: "/mall/tenant/merchant/product/returnPlat",
    method: "post",
    data: props
  });
};
export const getCount = data => {
  return request({
    url: "/mall/tenant/merchant/product/statisticsBySourceType",
    method: "post",
    data
  });
};

/**
 * 模板文件导入
 */
export const importTemplate = (filePath, data) => {
  return request({
    url: `/mall/mecrchant/file/importProductExcel?filePath=${filePath}`,
    method: "post",
    data
  });
};

/**
 * 下载模板
 */
export const downTempFile = categoryId => {
  return request({
    url: "/mall/mecrchant/file/exportProductExcel",
    method: "post",
    responseType: "blob",
    data: { categoryId }
  });
};
/**
 * 获取用户常用分类列表
 */
export const getUserCategoryList = () => {
  return request({
    url: "/mall/common/commonlyCategory/list",
    method: "post"
  });
};
/**
 * 保存常用分类
 */
export const saveOftenCategory = categoryId => {
  return request({
    url: "/mall/common/commonlyCategory/save",
    method: "post",
    data: { categoryId }
  });
};

/**
 * 上传记录
 */
export const getUploadRecord = data => {
  return request({
    url: "/mall/mecrchant/file/logs",
    method: "post",
    data
  });
};
/**
 * 删除导入日志
 */
export const deleteUploadRecord = id => {
  return request({
    url: "/mall/mecrchant/file/deleteLogs",
    method: "post",
    data: { id }
  });
};
/**
 * 商品管理-删除预发布-自有商品
 */
export const removePreReleaseProduct = props => {
  return request({
    url: "/mall/tenant/merchant/product/removePreReleaseProduct",
    method: "post",
    data: props
  });
};
/**
 * 商品管理-已上架的商品进行修复
 */
export const repairSku = props => {
  return request({
    url: "/mall/tenant/merchant/product/repairSku ",
    method: "post",
    data: props
  });
};
/**
 * 获取商品管理导入状态
 */
export const getInProgressCount = (type=1) => {
  return request({
    url: `/sass/consume/getInProgressCount/${type}`,
    method: "get"
  });
};
